home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / api.fr_ / api.fr
Text File  |  1995-07-19  |  10KB  |  316 lines

  1. VERSION 4.00
  2. Begin VB.Form frmODBC 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "ODBC Database"
  5.    ClientHeight    =   5820
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1470
  8.    ClientWidth     =   7365
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   6315
  19.    Left            =   990
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   5820
  22.    ScaleWidth      =   7365
  23.    Top             =   1080
  24.    Width           =   7575
  25.    Begin VB.ListBox lstODBCDrivers 
  26.       BackColor       =   &H00C0C0C0&
  27.       Height          =   1005
  28.       Left            =   240
  29.       Sorted          =   -1  'True
  30.       TabIndex        =   3
  31.       TabStop         =   0   'False
  32.       Top             =   2160
  33.       Width           =   4935
  34.    End
  35.    Begin VB.TextBox txtODBCStatus 
  36.       BackColor       =   &H00C0C0C0&
  37.       Height          =   315
  38.       Left            =   240
  39.       TabIndex        =   4
  40.       TabStop         =   0   'False
  41.       Top             =   4680
  42.       Width           =   6015
  43.    End
  44.    Begin VB.ListBox lstODBCDbs 
  45.       Height          =   1005
  46.       Left            =   240
  47.       TabIndex        =   1
  48.       Top             =   600
  49.       Width           =   4935
  50.    End
  51.    Begin VB.CommandButton cmdGetStatus 
  52.       Caption         =   "&Get ODBC Status"
  53.       Height          =   375
  54.       Left            =   240
  55.       TabIndex        =   5
  56.       Top             =   5280
  57.       Width           =   1695
  58.    End
  59.    Begin VB.CommandButton cmdQuit 
  60.       Caption         =   "&Quit"
  61.       Default         =   -1  'True
  62.       Height          =   375
  63.       Left            =   5040
  64.       TabIndex        =   6
  65.       Top             =   5280
  66.       Width           =   1215
  67.    End
  68.    Begin VB.Label lblDrivers 
  69.       BackColor       =   &H00C0C0C0&
  70.       Caption         =   "Installed ODBC Drivers:"
  71.       Height          =   255
  72.       Left            =   240
  73.       TabIndex        =   2
  74.       Top             =   1800
  75.       Width           =   3375
  76.    End
  77.    Begin VB.Label lblDatabases 
  78.       BackColor       =   &H00C0C0C0&
  79.       Caption         =   "&Registered ODBC Databases:"
  80.       Height          =   255
  81.       Left            =   240
  82.       TabIndex        =   0
  83.       Top             =   240
  84.       Width           =   3375
  85.    End
  86. End
  87. Attribute VB_Name = "frmODBC"
  88. Attribute VB_Creatable = False
  89. Attribute VB_Exposed = False
  90. Option Explicit
  91.  
  92. 'Dynamic arrays to hold data
  93. Dim dbName() As String
  94. Dim dbDesc() As String
  95. Dim DriverDesc() As String
  96. Dim DriverAttr() As String
  97.  
  98. Private Sub cmdGetStatus_Click()
  99.     Dim result As Integer
  100.  
  101.     'open the ODBC connection
  102.     result = ODBCAllocateEnv(ghEnv)
  103.     If result = SQL_SUCCESS Then
  104.         GetODBCdbs
  105.         GetODBCdvrs
  106.  
  107.         cmdGetStatus.Enabled = False
  108.         txtODBCStatus.text = "Click one of the registered databases to obtain info."
  109.     Else
  110.         txtODBCStatus.text = "ODBC Information could not be retrieved."
  111.         Exit Sub
  112.     End If
  113.  
  114. End Sub
  115.  
  116. Private Sub cmdQuit_Click()
  117.     End
  118. End Sub
  119.  
  120. Private Sub Form_Load()
  121.     txtODBCStatus.text = "Select Get ODBC Status to begin."
  122. End Sub
  123.  
  124. Private Sub Form_Resize()
  125.     If Me.WindowState = NORMAL Then
  126.         If frmODBC.ScaleHeight < (9 * cmdQuit.Height) Then
  127.             frmODBC.Height = (11 * cmdQuit.Height)
  128.         End If
  129.         If frmODBC.ScaleWidth < (2 * (cmdQuit.Width + cmdGetStatus.Width)) Then
  130.             frmODBC.Width = (2 * (cmdQuit.Width + cmdGetStatus.Width))
  131.         End If
  132.  
  133.         'Center the form
  134.         frmODBC.TOP = (Screen.Height - frmODBC.Height) / 2
  135.         frmODBC.Left = (Screen.Width - frmODBC.Width) / 2
  136.     End If
  137.     If Not (Me.WindowState = MINIMIZED) Then
  138.         RedrawForm
  139.     End If
  140. End Sub
  141.  
  142. Private Sub Form_Unload(Cancel As Integer)
  143.     'Clean up the ODBC connections and allocations
  144.     Dim result As Integer
  145.  
  146.     result = ODBCDisconnectDS(ghEnv, ghDbc, ghStmt)
  147.     result = ODBCFreeEnv(ghEnv)
  148. End Sub
  149.  
  150. Private Sub GetODBCdbs()
  151.     Dim cbDSNMax As Integer
  152.     Dim szDSN As String * 33
  153.     #If Win32 Then
  154.         Dim pcbDSN As Long
  155.         Dim pcbDescription As Long
  156.     #Else
  157.         Dim pcbDSN As Integer
  158.         Dim pcbDescription As Integer
  159.     #End If
  160.     Dim szDescription As String * 512
  161.     Dim cbDescriptionMax As Integer
  162.     Dim result As Integer
  163.     Dim i As Integer
  164.     Dim nameLen As Integer
  165.     Dim ErrResult
  166.     
  167.     cbDSNMax = SQL_MAX_DSN_LENGTH + 1
  168.     cbDescriptionMax = 512
  169.     result = SQL_SUCCESS
  170.     i = 0
  171.  
  172.     Screen.MousePointer = HOURGLASS
  173.     Do While result <> SQL_NO_DATA_FOUND
  174.         'Get next data source (on the first call to
  175.         'SQLDataSources, SQL_FETCH_NEXT gets the first
  176.         'data source
  177.         result = SQLDataSources(ghEnv, SQL_FETCH_NEXT, szDSN, cbDSNMax, pcbDSN, szDescription, cbDescriptionMax, pcbDescription)
  178.         If result = SQL_ERROR Then
  179.             ErrResult = ODBCError("Env", ghEnv, 0, 0, result, "Error getting list of data sources.")
  180.             Screen.MousePointer = DEFAULT
  181.             Exit Sub
  182.         End If
  183.         
  184.         ReDim Preserve dbName(i)
  185.         dbName(i) = Left(szDSN, pcbDSN)
  186.         ReDim Preserve dbDesc(i)
  187.         dbDesc(i) = Left(szDescription, pcbDescription)
  188.         
  189.         lstODBCdbs.AddItem dbName(i) & "  (" & dbDesc(i) & ")"
  190.         
  191.         i = i + 1
  192.     Loop
  193.     Screen.MousePointer = DEFAULT
  194.  
  195. End Sub
  196.  
  197. Private Sub GetODBCdvrs()
  198.     Dim szDriverDesc As String * 512
  199.     Dim cbDriverDescMax As Integer
  200.     #If Win32 Then
  201.         Dim pcbDriverDesc As Long
  202.     #Else
  203.         Dim pcbDriverDesc As Integer
  204.     #End If
  205.     Dim szDriverAttributes As String * 2048
  206.     Dim cbDrvrAttrMax As Integer
  207.     #If Win32 Then
  208.         Dim pcbDrvrAttr As Long
  209.     #Else
  210.         Dim pcbDrvrAttr As Integer
  211.     #End If
  212.     Dim i As Integer
  213.     Dim result As Integer
  214.     Dim ErrResult As Integer
  215.  
  216.     cbDriverDescMax = 512
  217.     cbDrvrAttrMax = 2048
  218.     result = SQL_SUCCESS
  219.     i = 0
  220.  
  221.     Do While result <> SQL_NO_DATA_FOUND
  222.         result = SQLDrivers(ghEnv, SQL_FETCH_NEXT, szDriverDesc, cbDriverDescMax, pcbDriverDesc, szDriverAttributes, cbDrvrAttrMax, pcbDrvrAttr)
  223.         If result = SQL_ERROR Then
  224.             ErrResult = ODBCError("Env", ghEnv, 0, 0, result, "Error getting list of registered drivers.")
  225.             Exit Sub
  226.         End If
  227.  
  228.         ReDim Preserve DriverDesc(i)
  229.         DriverDesc(i) = Left(szDriverDesc, pcbDriverDesc)
  230.         ReDim Preserve DriverAttr(i)
  231.         DriverAttr(i) = Left(szDriverAttributes, pcbDrvrAttr)
  232.         
  233.         lstODBCDrivers.AddItem DriverDesc(i) & "  (" & DriverAttr(i) & ")"
  234.         
  235.         i = i + 1
  236.     Loop
  237.  
  238. End Sub
  239.  
  240. Private Sub lstODBCDbs_Click()
  241.     Dim DataSource As String
  242.     Dim UserID As String
  243.     Dim Password As String
  244.     Dim result As Integer
  245.     Dim ErrResult As Integer
  246.     ReDim FuncList(100) As Integer
  247.     Dim i As Integer, j As Integer
  248.  
  249.     Screen.MousePointer = HOURGLASS
  250.     DataSource = dbName(lstODBCdbs.ListIndex)
  251.     
  252.     result = ODBCConnectDS(ghEnv, ghDbc, ghStmt, DataSource, UserID, Password)
  253.     If result <> SQL_SUCCESS Then
  254.         Screen.MousePointer = DEFAULT
  255.         Exit Sub
  256.     End If
  257.  
  258.     'Now get the list of functions
  259.     result = SQLGetFunctions(ghDbc, SQL_API_ALL_FUNCTIONS, FuncList(0))
  260.     If result <> SQL_SUCCESS Then
  261.         ErrResult = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Error getting list of ODBC functions")
  262.         Screen.MousePointer = DEFAULT
  263.         Exit Sub
  264.     End If
  265.  
  266.     Load frmAttributes
  267.  
  268.     j = 0
  269.     For i = 0 To 99
  270.         If FuncList(i) <> 0 Then
  271.             frmAttributes.lstFunctions.AddItem ODBCFuncs(0, i)
  272.             j = j + 1
  273.         End If
  274.     Next
  275.  
  276.     frmAttributes.txtFuncCount.text = j
  277.     frmAttributes.Caption = "Data Source: " & DataSource
  278.     
  279.     frmAttributes.Show MODAL
  280.  
  281.     'free the data source connection
  282.     result = ODBCDisconnectDS(ghEnv, ghDbc, SQL_NULL_HSTMT)
  283.  
  284.     Screen.MousePointer = DEFAULT
  285.  
  286. End Sub
  287.  
  288. Private Sub RedrawForm()
  289.     Dim LBHeight As Integer
  290.  
  291.     cmdQuit.TOP = frmODBC.ScaleHeight - (1.5 * cmdQuit.Height)
  292.     cmdQuit.Left = frmODBC.ScaleWidth - (1.25 * cmdQuit.Width)
  293.     cmdGetStatus.TOP = cmdQuit.TOP
  294.     cmdGetStatus.Left = 0.25 * cmdQuit.Width
  295.     
  296.     txtODBCStatus.Left = cmdGetStatus.Left
  297.     txtODBCStatus.Width = frmODBC.ScaleWidth - (0.5 * cmdQuit.Width)
  298.     txtODBCStatus.TOP = cmdQuit.TOP - (1.5 * cmdQuit.Height)
  299.     
  300.     'Area for each of two listbox:
  301.     LBHeight = (txtODBCStatus.TOP - lblDatabases.TOP) / 2.05
  302.  
  303.     lstODBCdbs.TOP = lblDatabases.TOP + (1.25 * lblDatabases.Height)
  304.     lstODBCdbs.Left = cmdGetStatus.Left
  305.     lstODBCdbs.Width = frmODBC.ScaleWidth - (0.5 * cmdQuit.Width)
  306.     lstODBCdbs.Height = LBHeight - (1.5 * lblDatabases.Height)
  307.  
  308.     lblDrivers.TOP = lblDatabases.TOP + LBHeight
  309.     lblDrivers.Height = lblDatabases.Height
  310.     lstODBCDrivers.TOP = lblDrivers.TOP + (1.25 * lblDrivers.Height)
  311.     lstODBCDrivers.Left = cmdGetStatus.Left
  312.     lstODBCDrivers.Width = frmODBC.ScaleWidth - (0.5 * cmdQuit.Width)
  313.     lstODBCDrivers.Height = LBHeight - (1.5 * lblDrivers.Height)
  314. End Sub
  315.  
  316.